home *** CD-ROM | disk | FTP | other *** search
- Path: news.NetVision.net.il!news
- From: Boazs@spl.co.il (Boaz Sdeor)
- Newsgroups: comp.lang.c
- Subject: Re: Can't figure this out
- Date: Mon, 22 Jan 1996 22:14:08 GMT
- Organization: NetVision LTD.
- Message-ID: <4e12rt$hnb@news.NetVision.net.il>
- References: <31000091.3778302@news.panix.com>
- NNTP-Posting-Host: ts3qp15.netvision.net.il
- X-Newsreader: Forte Free Agent 1.0.82
-
- dm@panix.com (Dan'l) wrote:
-
- >I am learning C and I have not had any problems understanding most
- >concepts I have learned so far. But to date I still can't figure out
- >how the outcome of this program is 15. Somehow one of the B's ends up
- >a three and the other B a 5, or am I so off base that I can't see
- >what's really happening. Can someone please walk me through this
- >one. Thanks Dan'l
-
- >#define A 3
- >#define B A + A
- >#define C B * B
-
- >main()
- >{
- > printf("%d", C);
- > return 0;
- >}
- Substitute B * B for C, and then A + A for B, you get :
-
- C --> A + A * A + A (no parethesis !), hence C = 3 + 3 * 3 + 3 =
- 3 + 9 + 3 = 15 !
-
- to get the correct answer, always use () in the #define , e.g.
- #define C (B) * (B) - and the problem disappears.
-
- Boaz.
-
-